package com.chushouya.order.constants;


import com.general.framework.core.enums.IEnum;
import com.general.framework.core.lang.Lists;
import com.chushouya.order.dto.admin.order.OrderQuery;

import java.util.List;
import java.util.Objects;

/**
 * 订单列表查询状态枚举
 * 0全部 1 进行中 3 已完成 4 已取消
 */
public enum UserOrderListLogicStatusEnum implements IEnum<Integer> {

    allCount(0,  "全部",   Lists.emptyList()),
    //待质检
    inProgress(1,  "待质检", Lists.asList(
            OrderStatusEnum.WAIT_QUALITY.value()
    )),
    //待支付
    toBePaid(2,  "待支付", Lists.asList(
            OrderStatusEnum.WAIT_PAY.value()
    )),
    //已完成
    complete(3,  "已完成", Lists.asList(OrderStatusEnum.COMPLETE.value())),
    ;

    private Integer logicStatus;

    private String logicStatusName;

    private List<Integer> statusList;

    UserOrderListLogicStatusEnum(Integer logicStatus, String logicStatusName, List<Integer> orderStatusList) {
        this.logicStatus = logicStatus;
        this.logicStatusName = logicStatusName;
        this.statusList = orderStatusList;
    }

    public static UserOrderListLogicStatusEnum get(Integer logicStatus) {
        for (UserOrderListLogicStatusEnum thisEnum : UserOrderListLogicStatusEnum.values()) {
            if (Objects.equals(thisEnum.logicStatus, logicStatus)) {
                return thisEnum;
            }
        }
        return UserOrderListLogicStatusEnum.allCount;
    }

    public static UserOrderListLogicStatusEnum getEnum(String logicStatusName) {
        for (UserOrderListLogicStatusEnum thisEnum : UserOrderListLogicStatusEnum.values()) {
            if (Objects.equals(thisEnum.name(), logicStatusName)) {
                return thisEnum;
            }
        }
        return UserOrderListLogicStatusEnum.allCount;
    }


    public OrderQuery buildQuery(OrderQuery query) {
        query.setOrderStatusList(this.statusList());
        return query;
    }

    public List<Integer> statusList() {
        return statusList;
    }

    @Override
    public Integer value() {
        return logicStatus;
    }

    @Override
    public String named() {
        return logicStatusName;
    }
}
